<?php 
//Security Checking for the user if allowed to login.
session_start();
if(strlen($_SESSION['u_name'])==0)
{
	?>
	<script>
	window.open("admin-login.php","_self");
	</script>
	<?php 
	exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
.body {
	background-color:#a6bf79;
	color:#000000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	margin: 10px 10px 10px 10px;
	padding: 0px;
}
.textLike
{
	color:#000000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	padding: 0px;
}
</style>
<title>Admin -New Listings</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="../js/jquery-1.4.2.js" type="text/javascript" language="javascript"></script>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<link href="../css/menu.css" rel="stylesheet" type="text/css" />
</head>
<body class="body">
<div id="body" style="width:960px;">
<div align="center">
<!-- Admin Home Page Menu Bar -->

<ul id="list-nav">
<li><a href="admin-homepage.php">Home</a></li>
<li><a href="admin-homepage.php">All Listings</a></li>
<!--<li><a href="approved-listing.php">Approved Listing</a></li>-->
<li><a href="unapproved-listing.php">Deactivated Listing</a></li>
<li><a href="new-listing.php">New Lists</a></li>
<li><a href="admin-themelist.php">Theme List</a></li>
<li><a href="secure.php?logout=yes">Log Out</a></li>
</ul>


<!-- Menu Bar Ends -->
</div>
<br />

<?php 
/*
 * Summary : Created By Avik on 18th April,2010
 * Version : 1.0
 * Contents: This file Shows All the data Admin Home page
 * Chnages
 */

#===========AUTHENTICATION========================#
session_start();
if(empty($_SESSION['u_name']))
{
	header("Location:admin-login.php");
}
//#########INCLUDE FILES########
include_once '../conf/db-config.php';
include_once '../conf/error.php';
include_once '../clsFetchData.php';
include_once '../array_to_xml.php';
//##############################

$objFetchData = new clsFetchData();
$arrAllUnApprovedDataToShow = array();
$arrCity = array();
$userid = $_SESSION['user_id'];	
$arrCity = $objFetchData->fetchCityForUser($userid);
unset($arrAllUnApprovedDataToShow);
//arrAllUnApprovedDataToShow  = $objFetchData->FetchDataToArray('b');

if(strtoupper($_SESSION['is_admin'])=='Y')
{
	$arrAllUnApprovedDataToShow  = $objFetchData->FetchDataToArray('b');
}
else
{
	if(count($arrCity)>0)
		$arrAllUnApprovedDataToShow  = $objFetchData->FetchDataToArrayWithCategories('b',$arrCity);
}
$heading = "Showing New Listings";



 
?>
<h3 style="padding-left: 50px;padding-bottom: 10px;"><u><i><?php echo $heading; ?></i></u></h3>
<?php 

/*
 * SHOW ALL UNAPPROVED DATA LISTINGS
 */

if(is_array($arrAllUnApprovedDataToShow) && count($arrAllUnApprovedDataToShow)>0)
{
	?>
	
	<table cellpadding="0" cellspacing="10" border="0" width="870" style="padding-left: 50px;">
	<tr>
		<td height="20px" align="right" style="padding-right: 0px;">
			<a href="changepassword.php">Change Password</a>
		</td>
	</tr>
	<?php 
	$icount=0;
	foreach ($arrAllUnApprovedDataToShow as $arrData)
	{
		if($icount%2==0)
		{
			?>
			<tr>
			<?php 
		}
		?>
		<td>
		<div id="topsection" style="margin: 0 auto;"></div>
		<div style="background:white;background-repeat: repeat-x;min-height:80px;width:400px;margin: 0 auto;height: auto;border-left:1px #35BAF5 solid;border-right:1px #35BAF5 solid;">
		<table width="400" cellpadding="5" cellspacing="0" border="0">
		<tr>
			<td colspan='2'><span style="color: #000;text-decoration: none;font-weight: bold;"><?php echo $arrData['business_title']; ?> </span> </td>
		</tr>
		<tr>
			<td width="200">
				<table cellpadding="0" cellspacing="0" width="100%" border="0">
					<tr>
						<td>
							<?php echo $arrData['street_address']; ?> 
							<br />
							<?php echo $arrData['city']."&nbsp;&nbsp;&nbsp;".$arrData['state']; ?>
						</td>
					</tr>
					
					<tr>
						<td>
							Category :<?php echo $arrData['theme']; ?> 
							<br />
							<?php echo $arrData['website_address']; ?> 
							<br />
							Phone: <?php echo $arrData['phone_number']; ?>
						</td>
					</tr>
					<tr>
						<td>
							<?php echo $arrData['business_desc']; ?> 
						</td>
					</tr>
				</table>
			</td>
			<td  width="200" align="center">
				<img src="<?php echo "../".$arrData['business_logo']; ?>" height="150" width="150" />
			</td>
		</tr>
		<tr>
		<?php if(strtoupper($arrData['is_approved'])=="N") { 
					$activate = " style='cursor: pointer;'";
					$deact ="style='cursor: pointer;'";
				}
				else
				{
					$activate="style='cursor: pointer;'";
					$deact ="style='cursor: pointer;'";
				}
				?>
			<td height="10" colspan="3">
				<input class="normalBtn" <?php echo $deact; ?> type="button" name="btnEdit" id="btnEdit" value=" Edit >>" onclick="editThis('<?php echo $arrData['sl_no']; ?>')" />
				&nbsp;&nbsp;
				<input class="normalBtn" <?php echo $deact; ?> type="button" name="btnSubmit" id="btnSubmit" value=" Approve >>" onclick="approveThis('<?php echo $arrData['sl_no']; ?>','<?php echo $arrData['city']; ?>','<?php echo $arrData['state'] ; ?>')" />
				&nbsp;&nbsp;
				<input class="normalBtn" type="button" name="btnDeactivate" id="btndDeactivate" value=" Deactivate >>" <?php echo $activate; ?> onclick="deactivateThis('<?php echo $arrData['sl_no']; ?>')" />
				&nbsp;&nbsp;
				<input class="normalBtn" type="button" name="btnDeactivate" id="btndDeactivate" value=" Delete >>" <?php echo "style='cursor: pointer;'"; ?> onclick="deleteThis('<?php echo $arrData['sl_no']; ?>')" />
			</td>
		</tr>
		
		</td>
		<?php 
		if($icount%2==1)
		{
			?>
			</tr>
			
			<?php 
		}
		else
		{
			?>
			
			<?php 
		}
		?>
		</table>
		</div>
		<div id="bottomsection"  style="margin: 0 auto;"></div>
		<?php 
		
		$icount++;
		
		}
		?>
		
	</table>
	<?php 
}
else
{
	print "<br />No New Data Found";
}



/*
 * XML REGENARATE WHEN FIND APPROVED
 */

if($_REQUEST['generate']=="yes")
{
	$arrAllUnApprovedDataToShow  = $objFetchData->FetchDataToArray('y');
	array_to_xml($arrAllUnApprovedDataToShow,1);	
}

?>
<script type="text/javascript">

	function editThis(id)
	{
		if(confirm("Do you really want to Edit this listing?"))
		{
			window.open('editListing.php?id='+id,'_self');
		}
		else
		{
			return false;
		}
	}

	function approveThis(id,city,state)
	{
		var random = (Math.random()*10000001);
		if(confirm("Do you really want to approve this ?"))
		{
			$.post("approveListing.php",{id:id,city:city,state:state},function(data)
					{
						//alert(data);return false;
						if(data==1)
						{
							window.open("admin-homepage.php?rand="+random+"&generate=yes","_self");
							//window.location.reload();
						}
						else
						{
							alert("There was a problem is saving. Please try later. Thank you");
						}
					},"text");
		}
	}

	function deactivateThis(id)
	{
		var random = (Math.random()*10000001);
		if(confirm("Do you really want to deactivate this ?"))
		{
			$.post("deactivateListing.php",{id:id},function(data)
					{
						if(data==1)
						{
							window.open("unapproved-listing.php?rand="+random+"&generate=yes","_self");
							//window.location.reload();
						}
						else
						{
							alert("There was a problem is saving. Please try later. Thank you");
						}
					},"text");
		}
	}

	function deleteThis(id)
	{
		var random = (Math.random()*10000001);
		if(confirm("Do you really want to delete this ?"))
		{
			$.post("deleteListing.php",{id:id},function(data)
					{
						if(data==1)
						{
							window.open("admin-homepage.php?rand="+random+"&generate=yes","_self");
						}
						else
						{
							alert("There was a problem is saving. Please try later. Thank you");
						}
					},"text");
		}
	}

	

</script>

</div>
</body>
</html>